package hikari.gui.panels.bullet;

import com.gooddies.events.ValueChangedEvent;
import com.gooddies.swing.RowLayout;
import com.gooddies.texteditors.DefaultFloatTextField;
import com.gooddies.wiring.annotations.WiringComponent;
import hikari.gui.guicomponents.hLabel;
import hikari.hcomponents.physics.PhysicsData;
import hikari.hcomponents.physics.SphereRigidBody;
import hikari.managers.Manager3D;
import hikari.math.CircleDrawer;
import org.swig.jirr.vector3df;

/**
 * @author sad
 */
@WiringComponent
public class BulletSphereRigidBodyPanel extends IBulletRigidBodyEditPanel {

    private DefaultFloatTextField radiusEB;
    private SphereRigidBody rigidBody;

    public BulletSphereRigidBodyPanel() {
        setTitle("Sphere Rigidbody");
    }

    public void init(PhysicsData data) {
        this.data = data;
        rigidBody = (SphereRigidBody) data.getRigidBody();
        setLayout(new RowLayout().setStartYGap(20).setStartXGap(10).setEndYGap(10));
        add(new hLabel("Radius"), RowLayout.NewRow);

        radiusEB = new DefaultFloatTextField(0, 9999999999f);
        radiusEB.setValueChangedEventNumber(new ValueChangedEvent<Float>() {
            @Override
            public void valueChanged(Float value) {
                onRadiusChanged(value);
            }
        });
        radiusEB.setValue(rigidBody.getRadius());
        add(radiusEB);
    }

    private void onRadiusChanged(float radius) {
        rigidBody.setRadius(radius);
    }

    @Override
    public void drawGizmo(Manager3D manager) {
        int segmentsCount = 15;
        CircleDrawer drawer = new CircleDrawer(segmentsCount, vector3df.NULLVECTOR, vector3df.DIR_RIGHT, rigidBody.getRadius());
        drawer.drawCircle();
        drawer = new CircleDrawer(segmentsCount, vector3df.NULLVECTOR, vector3df.DIR_UP, rigidBody.getRadius());
        drawer.drawCircle();
        drawer = new CircleDrawer(segmentsCount, vector3df.NULLVECTOR, vector3df.DIR_FRONT, rigidBody.getRadius());
        drawer.drawCircle();
    }
}
